import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_device_type/flutter_device_type.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tv_friso_screen/utils/result_check_utils.dart';
import 'package:tv_friso_screen/utils/share_pre_utils.dart';
import 'package:tv_friso_screen/utils/toast_utils.dart';

import 'model/response_with_object.dart';
import 'net/api_address.dart';
import 'net/data_helper.dart';
import 'net/http_manager.dart';

class ForgotPasswordPhonePadPage extends StatefulWidget {
  final String phoneStr;
  final String languageStr;

  const ForgotPasswordPhonePadPage(this.phoneStr, this.languageStr,
      {super.key});

  @override
  State<ForgotPasswordPhonePadPage> createState() =>
      _ForgotPasswordPhonePadPageState();
}

class _ForgotPasswordPhonePadPageState
    extends State<ForgotPasswordPhonePadPage> {
  var phoneController = TextEditingController();
  var codeController = TextEditingController();
  var pwdController = TextEditingController();
  var confirmPwdController = TextEditingController();

  var codeHintText = "获取验证码";
  var isCanSendCode = true;
  Timer? mTimer;
  var isTable = false;
  var currentLanguage = '';

  FocusNode focusNodeUser = FocusNode();
  FocusNode focusNodeCode = FocusNode();
  FocusNode focusNodePwd = FocusNode();
  FocusNode focusNodeSurePwd = FocusNode();

  void startTimer(int count) {
    mTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
      count--;
      setState(() {
        if (widget.languageStr == "zh") {
          codeHintText = "${count}s重新获取";
          if (count == 0) {
            mTimer!.cancel();
            codeHintText = "重新获取";
            isCanSendCode = true;
          }
        } else {
          codeHintText = "${count}s Retrieve";
          if (count == 0) {
            mTimer!.cancel();
            codeHintText = "Retrieve";
            isCanSendCode = true;
          }
        }
      });
    });
  }

  //检查能否提交
  checkPost(BuildContext context) {
    if (widget.languageStr == "zh") {
      if (phoneController.text.isEmpty) {
        ToastUtils.showToast("请输入账户");
        return;
      }
      if (codeController.text.isEmpty) {
        ToastUtils.showToast("请输入验证码");
        return;
      }
      if (pwdController.text.isEmpty) {
        ToastUtils.showToast("请设置新密码");
        return;
      }
      if (confirmPwdController.text.isEmpty) {
        ToastUtils.showToast("请再次输入新密码");
        return;
      }

      if (confirmPwdController.text != pwdController.text) {
        ToastUtils.showToast("两次密码输入不一致");
        return;
      }
    } else {
      if (phoneController.text.isEmpty) {
        ToastUtils.showToast("Please enter your account");
        return;
      }
      if (codeController.text.isEmpty) {
        ToastUtils.showToast("Please enter the verification code");
        return;
      }
      if (pwdController.text.isEmpty) {
        ToastUtils.showToast("Please set a new password");
        return;
      }
      if (confirmPwdController.text.isEmpty) {
        ToastUtils.showToast("Please enter the new password again");
        return;
      }

      if (confirmPwdController.text != pwdController.text) {
        ToastUtils.showToast("The two password inputs are inconsistent");
        return;
      }
    }

    postConfirm(context);
  }

  void getSendCode() async {
    var params = {
      "login_account_app": phoneController.text,
    };

    var formData = DataHelper.getBaseMapWithParamsWithoutToken(params);
    var response = await HttpManager().post(ApiAddress.getSendCode,
        query: DataHelper.getBaseMap(), params: formData);

    ResponseWithObject<Object> data =
        ResponseWithObject.fromJson(response as Map<String, dynamic>, (j) {
      return j;
    });

    if (data.code == HttpManager.codeSuccess) {
      startTimer(60);
      isCanSendCode = false;
      ToastUtils.showToast(data.msg);
    } else {
      isCanSendCode = true;
      ResultCheckUtils.checkResult(context, data.code, data.msg);
    }
  }

  //登录
  void postConfirm(BuildContext context) async {
    var params = {
      "login_account_app": phoneController.text,
      "ver_code": codeController.text,
      "password": pwdController.text,
      "password_repeat": confirmPwdController.text,
    };
    var formData = DataHelper.getBaseMapWithParamsWithoutToken(
        params); //DataHelper.getBaseMapParamsWithoutToken(params);
    var response =
        await HttpManager().post(ApiAddress.forgetPwd, params: formData);
    ResponseWithObject<Object> data =
        ResponseWithObject.fromJson(response as Map<String, dynamic>, (j) {
      return j;
    });

    if (data.code == HttpManager.codeSuccess) {
      if (widget.languageStr == "zh") {
        ToastUtils.showToast("密码重置成功");
      } else {
        ToastUtils.showToast("Password reset successful");
      }

      Navigator.pop(context);

      // Navigator.pop(context, {
      //   "phone": phoneController.text,
      //   "password": pwdController.text,
      // });
    } else {
      isCanSendCode = true;
      ResultCheckUtils.checkResult(context, data.code, data.msg);
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    phoneController.text = widget.phoneStr;
    if (widget.languageStr == "zh") {
      codeHintText = "获取验证码";
    } else {
      codeHintText = "Get SMS Code";
    }
    isTable = Device.get().isTablet;
    currentLanguage = widget.languageStr;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: currentLanguage == "zh"
          ? FocusScope(
              node: FocusScopeNode(),
              child: GestureDetector(
                onTap: () {
                  FocusScope.of(context).unfocus(); // 点击空白处收回键盘
                },
                child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  decoration: const BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(
                        "assets/images/icon_bg_login.jpg",
                      ),
                      fit: BoxFit.fill,
                    ),
                  ),
                  child: Stack(
                    children: [
                      Center(
                        child: SizedBox(
                          width: 612.w,
                          height: 676.w,
                          child: Text(
                            "重置密码",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 28.sp,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ),
                      Center(
                        child: Container(
                          width: 612.w,
                          height: 676.w,
                          padding: EdgeInsets.all(80.w),
                          decoration: const BoxDecoration(
                            image: DecorationImage(
                              image: AssetImage(
                                "assets/images/forget_password_bg.png",
                              ),
                              fit: BoxFit.fill,
                            ),
                          ),
                          child: SingleChildScrollView(
                            child: Column(
                              children: [
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 60.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "账号：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 160.w,
                                        height: 60.h,
                                        margin: EdgeInsets.only(
                                            right: 0.w, left: 40.w),
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodeUser),
                                          child: TextField(
                                            focusNode: focusNodeUser,
                                            keyboardType: TextInputType.phone,
                                            textAlign: TextAlign.left,
                                            controller: phoneController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                              FilteringTextInputFormatter
                                                  .digitsOnly, // 仅允许数字输入
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "请输入账户",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        width: 1.w,
                                        height: 40.h,
                                        color: Colors.grey,
                                      ),
                                      GestureDetector(
                                        onTap: () {
                                          if (phoneController.text.isEmpty) {
                                            ToastUtils.showToast("请输入账号");
                                          }
                                          if (isCanSendCode) {
                                            getSendCode();
                                          }
                                        },
                                        child: Container(
                                          margin: EdgeInsets.only(
                                              right: 0.w, left: 10.w),
                                          height: 60.h,
                                          child: Center(
                                            child: Text(
                                              codeHintText,
                                              textAlign: TextAlign.center,
                                              style: TextStyle(
                                                color: const Color.fromRGBO(
                                                    63, 161, 238, 1),
                                                fontSize: 17.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "验证码：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 220.w,
                                        margin: EdgeInsets.only(
                                            right: 20.w, left: 20.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodeCode),
                                          child: TextField(
                                            focusNode: focusNodeCode,
                                            keyboardType: TextInputType.number,
                                            textAlign: TextAlign.left,
                                            controller: codeController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "请输入验证码",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "新密码：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 220.w,
                                        margin: EdgeInsets.only(
                                            right: 20.w, left: 20.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodePwd),
                                          child: TextField(
                                            focusNode: focusNodePwd,
                                            textAlign: TextAlign.left,
                                            obscureText: true,
                                            controller: pwdController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "请设置你的新密码",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "确认密码：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 220.w,
                                        margin: EdgeInsets.only(right: 20.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) => FocusScope.of(
                                                  context)
                                              .requestFocus(focusNodeSurePwd),
                                          child: TextField(
                                            focusNode: focusNodeSurePwd,
                                            textAlign: TextAlign.left,
                                            controller: confirmPwdController,
                                            obscureText: true,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "请再次输入你的新密码",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                SizedBox(
                                  height: 20.w,
                                ),
                                GestureDetector(
                                  onTap: () {
                                    checkPost(context);
                                  },
                                  child: Container(
                                    margin: EdgeInsets.only(
                                        left: 40.w, right: 40.w, top: 40.w),
                                    child: Container(
                                      width: double.infinity,
                                      height: 62.w,
                                      decoration: BoxDecoration(
                                        gradient: const LinearGradient(
                                          colors: [
                                            Color.fromRGBO(83, 181, 255, 1),
                                            Color.fromRGBO(19, 107, 240, 1)
                                          ],
                                        ),
                                        borderRadius:
                                            BorderRadius.circular(5.w),
                                      ),
                                      child: Center(
                                        child: Text(
                                          "确定",
                                          style: TextStyle(
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold,
                                            fontSize: 24.sp,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 50.w,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: () {
                          Navigator.pop(context, {
                            "phone": "",
                            "password": "",
                          });
                        },
                        child: Align(
                          alignment: Alignment.topLeft,
                          child: Container(
                            width: 100.w,
                            height: 100.w,
                            margin: EdgeInsets.only(left: 10.w, top: 10.w),
                            child: Icon(
                              Icons.arrow_back_ios,
                              color: Colors.white,
                              size: 60.w,
                            ),
                          ),
                        ),
                      ),
                      Positioned(
                        left: 150.w,
                        top: 5.w,
                        child: Container(
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(8.w),
                              border: Border.all(
                                color: const Color.fromRGBO(3, 90, 168, 1),
                                width: 1.w, // 边框宽度
                              )),
                          child: Row(
                            children: [
                              GestureDetector(
                                onTap: () {
                                  SharePreUtils.setLanguage("zh");
                                  setState(() {
                                    currentLanguage = "zh";
                                  });
                                },
                                child: Container(
                                  width: 150.w,
                                  height: 55.w,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(8.w),
                                    color: currentLanguage == "zh"
                                        ? const Color.fromRGBO(30, 210, 255, 1)
                                        : Colors.transparent,
                                  ),
                                  padding:
                                      EdgeInsets.only(top: 8.w, bottom: 8.w),
                                  child: Text(
                                    "中文",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      color: currentLanguage == "zh"
                                          ? const Color.fromRGBO(8, 42, 51, 1)
                                          : const Color.fromRGBO(
                                              30, 210, 255, 1),
                                      fontSize: 28.sp,
                                      fontWeight: FontWeight.normal,
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () {
                                  SharePreUtils.setLanguage("en");
                                  setState(() {
                                    currentLanguage = "en";
                                  });
                                },
                                child: Container(
                                  width: 150.w,
                                  height: 55.w,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(8.w),
                                    color: currentLanguage == "en"
                                        ? const Color.fromRGBO(30, 210, 255, 1)
                                        : Colors.transparent,
                                  ),
                                  padding:
                                      EdgeInsets.only(top: 8.w, bottom: 8.w),
                                  child: Text(
                                    "English",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      color: currentLanguage == "en"
                                          ? const Color.fromRGBO(8, 42, 51, 1)
                                          : const Color.fromRGBO(
                                              30, 210, 255, 1),
                                      fontSize: 28.sp,
                                      fontWeight: FontWeight.normal,
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            )
          : FocusScope(
              node: FocusScopeNode(),
              child: GestureDetector(
                onTap: () {
                  FocusScope.of(context).unfocus(); // 点击空白处收回键盘
                },
                child: Container(
                  width: double.infinity,
                  height: double.infinity,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(
                        isTable
                            ? "assets/images/icon_pad_main_en_back.png"
                            : "assets/images/icon_phone_main_en_back.png",
                      ),
                      fit: BoxFit.fill,
                    ),
                  ),
                  child: Stack(
                    children: [
                      Center(
                        child: SizedBox(
                          width: 612.w,
                          height: 676.w,
                          child: Text(
                            "Reset Password",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 28.sp,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ),
                      Center(
                        child: Container(
                          width: 612.w,
                          height: 676.w,
                          padding: EdgeInsets.all(80.w),
                          decoration: const BoxDecoration(
                            image: DecorationImage(
                              image: AssetImage(
                                "assets/images/forget_password_bg.png",
                              ),
                              fit: BoxFit.fill,
                            ),
                          ),
                          child: SingleChildScrollView(
                            child: Column(
                              children: [
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 60.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "account：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 160.w,
                                        height: 60.h,
                                        margin: EdgeInsets.only(
                                            right: 0.w, left: 0.w),
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodeUser),
                                          child: TextField(
                                            focusNode: focusNodeUser,
                                            keyboardType: TextInputType.phone,
                                            textAlign: TextAlign.left,
                                            controller: phoneController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                              FilteringTextInputFormatter
                                                  .digitsOnly, // 仅允许数字输入
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "account",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                      Container(
                                        width: 1.w,
                                        height: 40.h,
                                        color: Colors.grey,
                                      ),
                                      GestureDetector(
                                        onTap: () {
                                          if (phoneController.text.isEmpty) {
                                            ToastUtils.showToast(
                                                "Please enter your account");
                                          }
                                          if (isCanSendCode) {
                                            getSendCode();
                                          }
                                        },
                                        child: Container(
                                          margin: EdgeInsets.only(
                                              right: 0.w, left: 20.w),
                                          height: 60.h,
                                          child: Center(
                                            child: Text(
                                              codeHintText,
                                              textAlign: TextAlign.center,
                                              style: TextStyle(
                                                color: const Color.fromRGBO(
                                                    63, 161, 238, 1),
                                                fontSize: 17.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "Captcha:",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 200.w,
                                        margin: EdgeInsets.only(
                                            right: 10.w, left: 10.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodeCode),
                                          child: TextField(
                                            focusNode: focusNodeCode,
                                            keyboardType: TextInputType.number,
                                            textAlign: TextAlign.left,
                                            controller: codeController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "verification code",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 20.w,
                                      ),
                                      Text(
                                        "New password：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 190.w,
                                        margin: EdgeInsets.only(
                                            right: 10.w, left: 10.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) =>
                                              FocusScope.of(context)
                                                  .requestFocus(focusNodePwd),
                                          child: TextField(
                                            focusNode: focusNodePwd,
                                            textAlign: TextAlign.left,
                                            obscureText: true,
                                            controller: pwdController,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "New password",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: double.infinity,
                                  height: 60.w,
                                  margin: EdgeInsets.only(
                                      top: 20.w, left: 20.w, right: 20.w),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5.w)),
                                  ),
                                  child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      SizedBox(
                                        width: 10.w,
                                      ),
                                      Text(
                                        "Confirm password：",
                                        style: TextStyle(
                                          color: const Color.fromRGBO(
                                            91,
                                            132,
                                            162,
                                            1,
                                          ),
                                          fontSize: 20.sp,
                                        ),
                                      ),
                                      Container(
                                        width: 190.w,
                                        margin: EdgeInsets.only(right: 10.w),
                                        height: 60.h,
                                        child: Listener(
                                          onPointerDown: (e) => FocusScope.of(
                                                  context)
                                              .requestFocus(focusNodeSurePwd),
                                          child: TextField(
                                            focusNode: focusNodeSurePwd,
                                            textAlign: TextAlign.left,
                                            controller: confirmPwdController,
                                            obscureText: true,
                                            style: TextStyle(
                                              color: const Color(0xff333333),
                                              fontSize: 20.sp,
                                            ),
                                            inputFormatters: [
                                              LengthLimitingTextInputFormatter(
                                                  11), // 限制输入长度为11位
                                            ],
                                            //将焦点绑定到TextFiled
                                            decoration: InputDecoration(
                                              isCollapsed: false,
                                              hintText: "New password again",
                                              hintStyle: TextStyle(
                                                fontSize: 17.sp,
                                                color: const Color(0xff999999),
                                              ),
                                              contentPadding: EdgeInsets.only(
                                                  left: 0.w,
                                                  right: 20.w,
                                                  top: 15.w),
                                              border: const OutlineInputBorder(
                                                  borderSide: BorderSide.none),
                                            ),
                                            cursorColor: Colors.blue,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                SizedBox(
                                  height: 20.w,
                                ),
                                GestureDetector(
                                  onTap: () {
                                    checkPost(context);
                                  },
                                  child: Container(
                                    margin: EdgeInsets.only(
                                        left: 40.w, right: 40.w, top: 40.w),
                                    child: Container(
                                      width: double.infinity,
                                      height: 62.w,
                                      decoration: BoxDecoration(
                                        gradient: const LinearGradient(
                                          colors: [
                                            Color.fromRGBO(83, 181, 255, 1),
                                            Color.fromRGBO(19, 107, 240, 1)
                                          ],
                                        ),
                                        borderRadius:
                                            BorderRadius.circular(5.w),
                                      ),
                                      child: Center(
                                        child: Text(
                                          "OK",
                                          style: TextStyle(
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold,
                                            fontSize: 24.sp,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 50.w,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: () {
                          Navigator.pop(context, {
                            "phone": "",
                            "password": "",
                          });
                        },
                        child: Align(
                          alignment: Alignment.topLeft,
                          child: Container(
                            width: 100.w,
                            height: 100.w,
                            margin: EdgeInsets.only(left: 10.w, top: 10.w),
                            child: Icon(
                              Icons.arrow_back_ios,
                              color: Colors.white,
                              size: 60.w,
                            ),
                          ),
                        ),
                      ),
                      Positioned(
                        left: 150.w,
                        top: 5.w,
                        child: Container(
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(8.w),
                              border: Border.all(
                                color: const Color.fromRGBO(3, 90, 168, 1),
                                width: 1.w, // 边框宽度
                              )),
                          child: Row(
                            children: [
                              GestureDetector(
                                onTap: () {
                                  SharePreUtils.setLanguage("zh");
                                  setState(() {
                                    currentLanguage = "zh";
                                  });
                                },
                                child: Container(
                                  width: 150.w,
                                  height: 55.w,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(8.w),
                                    color: currentLanguage == "zh"
                                        ? const Color.fromRGBO(30, 210, 255, 1)
                                        : Colors.transparent,
                                  ),
                                  padding:
                                      EdgeInsets.only(top: 8.w, bottom: 8.w),
                                  child: Text(
                                    "中文",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      color: currentLanguage == "zh"
                                          ? const Color.fromRGBO(8, 42, 51, 1)
                                          : const Color.fromRGBO(
                                              30, 210, 255, 1),
                                      fontSize: 28.sp,
                                      fontWeight: FontWeight.normal,
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () {
                                  SharePreUtils.setLanguage("en");
                                  setState(() {
                                    currentLanguage = "en";
                                  });
                                },
                                child: Container(
                                  width: 150.w,
                                  height: 55.w,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(8.w),
                                    color: currentLanguage == "en"
                                        ? const Color.fromRGBO(30, 210, 255, 1)
                                        : Colors.transparent,
                                  ),
                                  padding:
                                      EdgeInsets.only(top: 8.w, bottom: 8.w),
                                  child: Text(
                                    "English",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      color: currentLanguage == "en"
                                          ? const Color.fromRGBO(8, 42, 51, 1)
                                          : const Color.fromRGBO(
                                              30, 210, 255, 1),
                                      fontSize: 28.sp,
                                      fontWeight: FontWeight.normal,
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ),
    );
  }
}
